package com.newegg.nlp.util.corenlp.zh;

import com.newegg.nlp.util.corenlp.Filter;
import com.newegg.nlp.util.corenlp.Keyword;
import com.newegg.nlp.util.corenlp.Result;
import com.newegg.nlp.util.corenlp.TagHelp;

import edu.stanford.nlp.ling.IndexedWord;
import edu.stanford.nlp.semgraph.SemanticGraph;
import edu.stanford.nlp.semgraph.SemanticGraphEdge;
import edu.stanford.nlp.simple.Sentence;

public class Filter_nsubj implements Filter {

	@Override
	public Result filter(SemanticGraphEdge graphEdge, SemanticGraph graph, Sentence sentence) {
		Result result = new Result();
		if ("nsubj".equals(graphEdge.getRelation().getShortName())) { // 依赖关系
			IndexedWord source = graphEdge.getSource();
			IndexedWord target = graphEdge.getTarget();
			if (TagHelp.isJJ(source.tag()) && TagHelp.isNN(target.tag())) {
				result.addKeyword(new Keyword(target.value() + source.value(), source.value(), target.value()));
			}
		}
		return result;
	}

}
